package login;

import java.util.HashMap;

public class UserInfo {
	
	private HashMap<String, String> credentials;
	
	private String[] testUsers = { "Peter", "Hank", "Betty", "Lotte", "Lilly", "admin" };
	private String[] testHashes = { 
			HashUtil.hexHash("Pan"), 
			HashUtil.hexHash("Williams"),
			HashUtil.hexHash("b4711"),
			HashUtil.hexHash("Lenya"),
			HashUtil.hexHash("hurra"),
			HashUtil.hexHash("password")
	};
	
	
	private static UserInfo instance = null;
	
	public static UserInfo getInstance() {
		if (instance == null) instance = new UserInfo();
		
		return instance;
	}
	
	private UserInfo() {
		credentials = new HashMap<String, String>();
		
		for (int i = 0; i < testUsers.length; i ++)
			credentials.put(testUsers[i], testHashes[i]);
		
	}
	
	public boolean isExistingUser(String username, String passwordHash) {
		String existingHash = credentials.get(username);
		
		if (existingHash == null) return false;
		
		else return passwordHash.equals(existingHash);
	}
	
	public boolean addUser(String username, String passwordHash) {
		if (credentials.get(username) == null) {
			credentials.put(username, passwordHash);
			return true;
		}
		
		else return false;
	}

}